import i18n from "@/locale";
import dayjs from "dayjs"

const $t = i18n.global.t

export function formatMenuTree(list) {
    return list.filter(father => {
        const childArr = list.filter(child => father.id === child.parentId)
        if (childArr.length > 0) {
            father.children = childArr
        }
        return father.parentId === 0
    })
}

/**
 *  日期区间查询处理 包头包尾
 * @param timeStampArr {Array}
 * @return {*}
 */
export function dateFormatTimeStamp(timeStampArr) {
    const [beforeDate, afterData] = timeStampArr || []
    if (beforeDate && afterData) {
        return [beforeDate, (parseInt(afterData) + (24 * 60 * 60 * 1000)).toString()]
    } else {
        return []
    }
}

/**
 * 获取时间区间
 * num 提前的天数
 * @returns {Array}
 */
export function defaultTimeDate(num = 7, fmt = 'YYYY-MM-DD') {
    const daysNum = dayjs().date()
    const beforeDate = dayjs().date(daysNum - (num - 1))
    return [beforeDate.$d.getTime(), new Date().getTime()]
}

/**
 *  获取营销结果
 * @return {Array}
 */
export function getMarketCause() {
    return [{
        "code": 0,
        "isRemark": 0,
        "key": "MarketingCauseEnum.ANSWER",
        "type": 1,
        "value": $t("接听")
    },
        {"code": 1, "isRemark": 0, "key": "MarketingCauseEnum.INTENTION", "type": 1, "value": $t('意向')}, {
            "code": 2,
            "isRemark": 0,
            "key": "MarketingCauseEnum.NO_DEMAND",
            "type": 1,
            "value": $t("暂无需求")
        },
        {"code": 3, "isRemark": 0, "key": "MarketingCauseEnum.ZALO", "type": 1, "value": $t('正在whatsapp上跟进')}, {
            "code": 5,
            "isRemark": 0,
            "key": "MarketingCauseEnum.PRODUCT_DISSATISFIED",
            "type": 1,
            "value": $t("产品不满意")
        }, {"code": 0, "isRemark": 0, "key": "MarketingCauseEnum.MISSED_CALL", "type": 2, "value": $t('未接听')}, {
            "code": 1,
            "isRemark": 0,
            "key": "MarketingCauseEnum.SHUT_DOWN",
            "type": 2,
            "value": $t("关机")
        }, {"code": 2, "isRemark": 0, "key": "MarketingCauseEnum.MISSED", "type": 2, "value": $t('未接')}, {
            "code": 3,
            "isRemark": 0,
            "key": "MarketingCauseEnum.REJECT",
            "type": 2,
            "value": $t("拒接")
        }, {
            "code": 4,
            "isRemark": 0,
            "key": "MarketingCauseEnum.ZALO_FOLLOW_UP",
            "type": 2,
            "value": $t("正在Zalo上跟进")
        }, {"code": 0, "isRemark": 0, "key": "MarketingCauseEnum.INVALID_NUMBER", "type": 3, "value": $t('无效号码')}, {
            "code": 1,
            "isRemark": 0,
            "key": "MarketingCauseEnum.EMPTY_NUMBER",
            "type": 3,
            "value": $t("空号")
        }, {"code": 2, "isRemark": 0, "key": "MarketingCauseEnum.BLOCKLIST", "type": 3, "value": $t('黑名单')}, {
            "code": 3,
            "isRemark": 0,
            "key": "MarketingCauseEnum.IPHONE",
            "type": 3,
            "value": $t("苹果手机")
        }]
}
